package com.kmproject.haifu.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IView;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.ConvenientPaymentRecordBean;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 08/30/2019 19:03
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class ConvenientPaymentRecordDetailActivity extends BaseActivity implements IView {
    @BindView(R.id.toolbar_backImg)
    ImageView toolbarBackImg;
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.back_right_icon)
    ImageView backRightIcon;
    @BindView(R.id.back_right_txt)
    TextView backRightTxt;
    @BindView(R.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;
    @BindView(R.id.tv_total_amount)
    TextView tvTotalAmount;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.tv_service_provider)
    TextView tvServiceProvider;
    @BindView(R.id.tv_service_no_l)
    TextView tvServiceNoL;
    @BindView(R.id.tv_service_no)
    TextView tvServiceNo;
    @BindView(R.id.tv_mobile_l)
    TextView tvMobileL;
    @BindView(R.id.tv_mobile)
    TextView tvMobile;
    @BindView(R.id.ll_mobile)
    LinearLayout llMobile;
    @BindView(R.id.tv_date_expiry)
    TextView tvDateExpiry;
    @BindView(R.id.ll_date_expiry)
    LinearLayout llDateExpiry;
    @BindView(R.id.tv_create_time)
    TextView tvCreateTime;
    @BindView(R.id.tv_amount_l)
    TextView tvAmountL;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.ll_price)
    LinearLayout llPrice;
    @BindView(R.id.tv_pay_way)
    TextView tvPayWay;
    @BindView(R.id.tv_exchange_rate)
    TextView tvExchangeRate;
    private ConvenientPaymentRecordBean mConvenientPaymentRecordBean;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_convenient_payment_record_detail; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        Intent intent = getIntent();
        mConvenientPaymentRecordBean = intent.getParcelableExtra("convenientPaymentRecordBean");
        showDetail(mConvenientPaymentRecordBean);
    }

    private void showDetail(ConvenientPaymentRecordBean convenientPaymentRecordBean) {
        tvOrderNo.setText(convenientPaymentRecordBean.getInvestId());
        tvServiceProvider.setText(convenientPaymentRecordBean.getServiceProvider());
        tvServiceNo.setText(convenientPaymentRecordBean.getAccountNumber());
        tvCreateTime.setText(convenientPaymentRecordBean.getPayTime());
        tvPayWay.setText(convenientPaymentRecordBean.getPayWayName());
        tvExchangeRate.setText("1:" + convenientPaymentRecordBean.getExchangeRate());
        switch (convenientPaymentRecordBean.getInvestType()) {//充值类型：mobile话费，electricity电费，water水费,network网费
            case "mobile":
                tvMobileL.setText("充值号码");
                if (!StringUtils.isEmpty(convenientPaymentRecordBean.getMobile())) {
                    tvMobile.setText(convenientPaymentRecordBean.getMobile());
                }
                tvAmountL.setText("充值金额");
                tvAmount.setText(convenientPaymentRecordBean.getTotalMoney());
                llPrice.setVisibility(View.VISIBLE);
                tvPrice.setText(convenientPaymentRecordBean.getActuallyPayMoney());
                llDateExpiry.setVisibility(View.GONE);
                break;
            case "electricity":
                llPrice.setVisibility(View.GONE);
                llMobile.setVisibility(View.GONE);
                tvDateExpiry.setText(convenientPaymentRecordBean.getExpirationTime());
                break;
            case "water":
                llDateExpiry.setVisibility(View.GONE);
                llMobile.setVisibility(View.GONE);
                llPrice.setVisibility(View.GONE);
                break;
            case "network":
                if (!StringUtils.isEmpty(convenientPaymentRecordBean.getMobile())) {
                    tvMobile.setText(convenientPaymentRecordBean.getMobile());
                }
                llDateExpiry.setVisibility(View.GONE);
                break;
        }
        tvAmount.setText(convenientPaymentRecordBean.getTotalMoney() + "P");
        tvTotalAmount.setText("¥" + convenientPaymentRecordBean.getActuallyPayMoney());
        if (convenientPaymentRecordBean.getOrderStatus() == 1) {
            tvStatus.setText("交易成功");
        } else {
            tvStatus.setText("未支付");
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
